# # 作业一：
# # 在服务器上自己的crmeb
# # 1、登录
# # 2、添加用户分组——》删除刚才新增的用户分组
# # 3、添加是否成功，断言；删除是否成功，断言
# # 组件化，元素与脚本分离
#
# import time
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support.ui import WebDriverWait
# from selenium.webdriver.support import expected_conditions as EC
# from ele0512 import *  #与ele同名，但需要是py文件
# """
# class CrmebGroup:
#     def __init__(self,url,brwoser):
#         self.brwoser=brwoser
#         self.brwoser.get(url)
#         self.brwoser.maximize_window()
#         self.brwoser.implicitly_wait(15)
#     def login(self,username,password):
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located(user_ele))[0].send_keys(username)
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located(pwd_ele))[1].send_keys(password)
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_element_located(lo_btn)).click()
#     def add_group(self, groupName):
#         self.groupName = groupName
#         time.sleep(5)
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located(u_btn))[1].click()
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_element_located(userGroup_ele)).click()
#         time.sleep(2)
#         # 点击添加分组
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_element_located(add_group_ele)).click()
#         # 等待弹窗弹出
#         time.sleep(2)
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located(input_group_ele))[2].send_keys(
#             self.groupName)
#         # 点击确定按钮
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located(accept_ele))[2].click()
#         # 等待新增
#         time.sleep(3)
#
#     def assert_add(self):
#         # 判断是否添加成功
#         text = WebDriverWait(self.brwoser, 10, 0.5).until(
#             EC.presence_of_element_located((By.XPATH, f"//*[text()='{self.groupName}']"))).text
#         assert text == self.groupName
#
#     def delete_group(self):
#         # 删除刚才新增过的
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located(delete_ele))[-1].click()
#         # 点击删除确认按钮
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located(ele_accept_ele))[-1].click()
# if __name__ == '__main__':
#     driver = webdriver.Chrome()
#     url = "http://115.29.179.199:8899/admin/login?redirect=%2Fadmin%2Findex"
#     c1 = CrmebGroup(url, driver)
#     c1.login("admin", "123456")
#     c1.add_group("0512作业")
#     c1.assert_add()
#     c1.delete_group()
#     """
"""
# # 作业三-crmeb：# # 1、添加用户标签——》删除刚才新增的用户标签
# # 2、添加是否成功，断言；删除是否成功，断言
"""
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from ele0512 import *  #与ele同名，但需要是py文件
class CrmebGroup:
    def __init__(self,url,brwoser):
        self.brwoser=brwoser
        self.brwoser.get(url)
        self.brwoser.maximize_window()
        self.brwoser.implicitly_wait(20)
    def login(self,username,password):
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located(user_ele))[0].send_keys(username)
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located(pwd_ele))[1].send_keys(password)
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_element_located(lo_btn)).click()

    def userbiaoqian(self):
        time.sleep(5)
        # 点击用户
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located(u_btn))[1].click()
        time.sleep(5)
        # 点击用户标签
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_element_located(userbiaoqian_ele)).click()
        time.sleep(5)
#        点击添加用户标签
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_element_located(adduserbiaoqian_ele)).click()
        time.sleep(5)
#

if __name__ == '__main__':
    driver = webdriver.Chrome()
    url = "http://115.29.179.199:8899/admin/login?redirect=%2Fadmin%2Findex"
    c1 = CrmebGroup(url, driver)
    c1.login("admin", "123456")
    c1.userbiaoqian()
    time.sleep(8)
    """    
# 点击添加分组
# WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_element_located(add_group_ele)).click()
# # 实例化驱动
# driver = webdriver.Chrome()
# # 打开网页
# driver.get("http://115.29.179.199:8899/admin/login?redirect=%2Fadmin%2Findex")
# # 浏览器全屏化
# driver.maximize_window()
# time.sleep(5)
# # 设置隐式等待
# driver.implicitly_wait(15)
# # 登录
# # 输入账号
# driver.find_elements(By.CLASS_NAME,"el-input__inner")[0].send_keys("admin")
# # 输入密码
# driver.find_elements(By.CLASS_NAME,"el-input__inner")[1].send_keys("123456")
# time.sleep(3)
# # 点击登录按钮
# driver.find_element(By.XPATH,"//*[text()='登录']").click()
# time.sleep(5)
# # 点击用户
# driver.find_elements(By.CLASS_NAME,"font12")[1].click()
# time.sleep(2)
# # 点击用户分组
# driver.find_element(By.XPATH,"//*[text()='用户分组']").click()
# time.sleep(3)
# # # 点击添加分组
# # driver.find_element(By.XPATH,"//*[text()='添加分组']").click()
# # time.sleep(3)
# # # 输入分组中内容
# # driver.find_elements(By.CLASS_NAME,"el-input__inner")[2].send_keys("0512作业")
# # time.sleep(4)
# # # 点击确定添加
# # driver.find_elements(By.CLASS_NAME,"el-button")[2].click()
# # time.sleep(5)
# # 删除刚才新增的用户分组
# # 点击删除
# driver.find_element(By.XPATH,"//*[@id='app']/section/div[2]/section/div/div[1]/div/main/div/div[1]/div/div[1]/div/div/div/div[2]/div[4]/div[2]/table/tbody/tr[5]/td[3]/div/a[2]").click()
# time.sleep(5)
# # 点击确定删除按钮
# driver.find_elements(By.CLASS_NAME,"el-button")[2].click()
# time.sleep(5)
# # 添加是否成功，断言；删除是否成功，断言
# text = driver.find_element(By.XPATH,"//*[@id='app']/section/div[2]/section/div/div[1]/div/main/div/div[1]/div/div[1]/div/div/div/div[2]/div[3]/table/tbody/tr[5]/td[2]/div/span").text
# assert text =="0512作业"
# print("删除成功")
"""
#
"""
# 作业二：
# QQ音乐登录：https://y.qq.com/portal/pop_login.html
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
# 实例化驱动
driver = webdriver.Chrome()
# 打开网页
driver.get("https://y.qq.com/portal/pop_login.html")
# 页面全屏
driver.maximize_window()
# 设置隐式等待
driver.implicitly_wait(15)
# 定位iframe内联框架
iframe = driver.find_elements(By.TAG_NAME,"iframe")
time.sleep(6)
# 跳进iframe
driver.switch_to.frame(iframe[0])
time.sleep(5)
#点击登录
driver.find_element(By.ID,"img_out_308768698").click()
time.sleep(5)
"""

# class QQMusic:
#     def __init__(self,url,brwoser):
#         self.brwoser=brwoser
#         self.brwoser.get(url)
#         self.brwoser.maximize_window()
#         self.brwoser.implicitly_wait(15)
#     def login(self,username,password):
#         WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located(user_ele))[0].send_keys(username)
#         WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located(pwd_ele))[1].send_keys(password)
#         WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_element_located(lo_btn)).click()
#
# if __name__ == '__main__':
#         driver = webdriver.Chrome()
#         url = "https://y.qq.com/portal/pop_login.html"
#         c1 =QQMusic(url, driver)
#         c1.login("308768698", "18941876068")

